package q287_findDuplicate;

public class Solution_3 {
    /*
    这个也可以用快慢指针
    如果我们让两个指针不停的向当前位置所指向的index移动 总有一次两者会相遇
     */
    public int findDuplicate(int[] nums) {
        int slow = 0, fast = 0;
        do {
            slow = nums[slow];
            fast = nums[nums[fast]];
        } while (slow != fast);
        
        slow = 0;
        while (slow != fast) {
            slow = nums[slow];
            fast = nums[fast];
        }
        return slow;
    }
}
